from __future__ import unicode_literals
from django.db import models
from django.db.models import permalink


# 文章类别
class Category(models.Model):
    # 文章类别的名称
    name = models.CharField(verbose_name='文章类别', max_length=50)

    class Meta:
        verbose_name = '文章类别'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Tag(models.Model):
    # 文章标签
    name = models.CharField(max_length=50, verbose_name='文章标签')

    class Meta:
        verbose_name = '文章标签'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Blog(models.Model):
    title = models.CharField(max_length=50, verbose_name='标题')
    content = models.TextField(default='', verbose_name='正文')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
    click = models.IntegerField(default=0, verbose_name='点击量')
    category = models.ForeignKey(Category, verbose_name='文章类别')
    tag = models.ForeignKey(Tag, verbose_name='文章标签')

    class Meta:
        verbose_name = '博客'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class Comment(models.Model):
    name = models.CharField(max_length=20, default='匿名', verbose_name='昵称')
    content = models.CharField(max_length=300, default='评论')
    blog = models.ForeignKey(Blog, verbose_name='文章')
    creat_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '评论'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content[:10]
